package com.fqgj.sentry.policy.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.sentry.policy.dao.PcColumnDao;
import com.fqgj.sentry.policy.dao.param.ColumnMap;
import com.fqgj.sentry.policy.entity.PcColumnEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * User: liupengpeng
 * Date: 2017-07-25
 * Time: 15:42:44.766
 */

@Repository
public class PcColumnDaoImpl extends AbstractBaseMapper<PcColumnEntity> implements PcColumnDao {
    @Override
    public PcColumnEntity selectByMerchantIdAndColumnCode(Long merchantId, String columnCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("merchantId", merchantId);
        map.put("columnCode", columnCode);
        return getSqlSession().selectOne(getStatement("selectByMerchantIdAndColumnCode"), map);
    }

    @Override
    public List<PcColumnEntity> selectColumnList(ColumnMap columnMap) {
        return getSqlSession().selectList(getStatement("selectColumnList"), columnMap);
    }


    @Override
    public List<PcColumnEntity> selectByEventId(Long eventId, Integer columnType) {
        Map<String, Object> param = new HashMap<>();
        param.put("eventId", eventId);
        param.put("columnType", columnType);
        return getSqlSession().selectList(getStatement("selectByEventId"), param);
    }

    @Override
    public Integer deleteBuColumnCode(Long merchantId, String columnCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("merchantId", merchantId);
        param.put("columnCode", columnCode);
        return getSqlSession().update(getStatement("deleteByColumnCode"), param);
    }

    @Override
    public List<PcColumnEntity> selectByMerchantIdAndEventId(Long merchantId,
                                                             List<Long> eventIds,
                                                             Integer columnType) {
        Map<String, Object> param = new HashMap<>();
        param.put("merchantId", merchantId);
        param.put("eventIds", CollectionUtils.isEmpty(eventIds) ? null : StringUtils.join(eventIds, ","));
        param.put("columnType", columnType);
        return getSqlSession().selectList(getStatement("selectByMerchantIdAndEventId"), param);
    }

    @Override
    public List<PcColumnEntity> selectByModuleCodes(List<String> moduleCodes) {
        Map<String, Object> param = new HashMap<>();
        param.put("moduleCodes", moduleCodes);
        return getSqlSession().selectList(getStatement("selectByModuleCodes"), param);
    }

    @Override
    public List<PcColumnEntity> selectListByColumCodes(Set<String> columnCodes) {
        Map<String, Object> param = new HashMap<>();
        param.put("columnCodes", columnCodes);
        return getSqlSession().selectList(getStatement("selectListByColumCodes"), param);
    }
}